# load packages
# List of required packages
required_packages <- c("tidyverse", "rdd", "jtools", "tidyr", "ggpubr", 
                       "rdrobust", "rddtools", "factoextra", "sandwich", 
                       "rdpower", "interflex", "metafor", "forcats", "haven")

# Check if each package is installed, and install if not
for (pkg in required_packages) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    install.packages(pkg, dependencies = TRUE)
  }
}

# Load the installed packages
library(tidyverse)
library(rdd)
library(jtools)
library(tidyr)
library(ggpubr)
library(rdrobust)
library(rddtools)
library(factoextra)
library(sandwich)
library(rdpower)
library(interflex)
library(metafor)
library(forcats)
library(haven)